//////////////////good-add 页面
layui.use(['form', 'laydate', 'upload', 'element'], function() {
	var $ = layui.jquery
	var form = layui.form,
		layer = layui.layer,
		upload = layui.upload,
		laydate = layui.laydate,
		element = layui.element; //Tab的切换功能，切换事件监听等，需要依赖element模块
	//普通图片上传
	var uploadInst = upload.render({
		elem: '#photo1',
		url: '/upload/',
		before: function(obj) {
			//预读本地文件示例，不支持ie8
			obj.preview(function(index, file, result) {
				$('#photo1_show').attr('src', result); //图片链接（base64）
			});
		},
		done: function(res) {
			//如果上传失败
			if(res.code > 0) {
				return layer.msg('上传失败');
			}
			//上传成功
		},
		error: function() {
			//演示失败状态，并实现重传
			/*var demoText = $('#demoText');
			demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
			demoText.find('.demo-reload').on('click', function() {
				uploadInst.upload();
			});*/
		}
	});
	//商品多图上传
	upload.render({
		elem: '#photo2',
		url: '/upload/',
		multiple: true,
		before: function(obj) {
			//预读本地文件示例，不支持ie8
			obj.preview(function(index, file, result) {
				$('#photo2_show').append('<img src="' + result + '" alt="' + file.name + '" class="layui-upload-img">')
			});
		},
		done: function(res) {
			if(res.code == 0) {
				return layer.msg('上传成功');
			}
		}
	});
	//商品单视频上传
	upload.render({
		elem: '#test5',
		url: '/upload/',
		accept: 'video' //视频
			,
		done: function(res) {
			console.log(res)
		}
	});
});